package com.csyaonie.android.listview;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.csyaonie.android.R;

public class MyListViewAdapter extends BaseAdapter {

    private Context mContext;
    private LayoutInflater mLayoutInflater;

    public MyListViewAdapter(Context context){
        this.mContext=context;
        this.mLayoutInflater=LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return 10;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    public class ViewHoder{
        public ImageView lviv1;
        public TextView lvtv1,lvtv2,lvtv3;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHoder viewHoder= null;
        if(convertView==null){
            convertView=mLayoutInflater.inflate(R.layout.list_view_item,null);
            viewHoder=new ViewHoder();
            viewHoder.lviv1=convertView.findViewById(R.id.lviv1);
            viewHoder.lvtv1=convertView.findViewById(R.id.lvtv1);
            viewHoder.lvtv2=convertView.findViewById(R.id.lvtv2);
            viewHoder.lvtv3=convertView.findViewById(R.id.lvtv3);
            convertView.setTag(viewHoder);
        }else{
            viewHoder= (ViewHoder) convertView.getTag();
        }
        Glide.with(mContext).load("https://www.baidu.com/img/PCfb_5bf082d29588c07f842ccde3f97243ea.png").into(viewHoder.lviv1);
        viewHoder.lvtv1.setText("title 标题");
        viewHoder.lvtv2.setText("1989-12-13");
        viewHoder.lvtv3.setText("这是内容哦");

        return convertView;
    }
}
